package com.fc.controller;

import com.fc.dto.VehicleIncomeDTO;
import com.fc.result.Result;
import com.fc.service.VehicleIncomeService;
import com.fc.vo.VehicleIncomeDetailVO;
import com.fc.vo.VehicleIncomeVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Set;

@Api(tags = "车辆收支分析")
@RestController
@RequestMapping("/vehicleIncome")
public class VehicleIncomeController {

    @Autowired
    private VehicleIncomeService vehicleIncomeService;

    /**
     * 查询某个车辆详细的收支分析
     *
     * @return
     */
    @PreAuthorize("hasRole('ADMIN')")
    @ApiOperation("查询车辆列表")
    @GetMapping
    public Result<Set<String>> listVehicle() {
        Set<String> vehicles = vehicleIncomeService.listVehicle();
        return Result.success(vehicles);
    }


    /**
     * 查询车辆收支分析列表
     *
     * @param vehicleIncomePageQueryDTO
     * @return
     */
    @PreAuthorize("hasRole('ADMIN')")
    @ApiOperation("查询车辆收支分析列表")
    @PostMapping("/list")
    public Result<List<VehicleIncomeVO>> list(@RequestBody VehicleIncomeDTO vehicleIncomePageQueryDTO) {
        List<VehicleIncomeVO> vehicleIncomeVOList = vehicleIncomeService.list(vehicleIncomePageQueryDTO);
        return Result.success(vehicleIncomeVOList);
    }


    /**
     * 查询某个车辆详细的收支分析
     *
     * @param vehiclePlate
     * @return
     */
    @PreAuthorize("hasRole('ADMIN')")
    @ApiOperation("查询某个车辆详细的收支分析")
    @GetMapping("/{vehiclePlate}")
    public Result<VehicleIncomeDetailVO> detail(@PathVariable String vehiclePlate) {
        VehicleIncomeDetailVO vehicleIncomeDetailVO = vehicleIncomeService.detail(vehiclePlate);
        return Result.success(vehicleIncomeDetailVO);
    }
}
